#pragma once
#include "Vector3f.h"
#include <iostream>
#include "Physics.h"
#include <GLFrame.h>
#include <GLGeometryTransform.h>
#include "Camera.h"
#include <GLTools.h>
#include "loaders.h"


class PhysicalObject
{

protected:
	//physics stuff
	float mass;
	Vector3f position;
	Vector3f centreOfGravity;
	Vector3f velocity;
	Vector3f *bbox;
	void createDefaultBbox();
	Vector3f totalForce;
	//rendering stuff
	float rotationangle;
	GLGeometryTransform *pGLGT;
	GLBatch myBatch;
	GLTriangleBatch *myTBatch;
	GLFrame myFrame;
	float scaleValue;
	GLuint *myTex;
	GLuint myShader;
	GLint locAmbient;
	GLint locDiffuse;
	GLint locSpecular;
	GLint locLight ;
	GLint locMVP;
	GLint locMV ;
	GLint locNM  ;
	GLint locTexture;
	int numParts;
	bool multipart;
	
	bool grav;

	float min_x;
	float max_x;
	float min_y;
	float max_y;
	float min_z;
	float max_z;
	float height;
	float width;
	float depth;


	float alignment;
public:
	//default.
	PhysicalObject();
	//Note bounding box must be specifically set in both constructors as
	//this class has no idea what shape the object is.
	//In both case the bounding box will simply be a 1x1 cube around the objects position.
	PhysicalObject(float m, Vector3f p, Vector3f cog, Vector3f v,char* fname, bool multi = true);
	//Mass
	void setMass(float newMass);
	float getMass();
	//Position
	Vector3f getPos();
	void setPos(Vector3f newPos);
	void setPos(float x, float y, float z);
	//Centre of gravity
	Vector3f getCOG();
	void setCOG(Vector3f newCOG);
	void setCOG(float x, float y, float z);
	//Velocity
	Vector3f getVel();
	void setVel(Vector3f newVel);
	void setVel(float x, float y, float z);
	//Bounding box.
	//must pass array of 2 'Vector3f's to be filled as cannot return an array.
	void getBbox(Vector3f* pbbox);
	void setBbox(Vector3f* newBbox);

	void enableGravity(){grav=true;}
	void disableGravity(){grav=false;}

	void addForce(Vector3f force);
	void exchangeMomentum(PhysicalObject* otherObject);
	// needs to be able to find the minx and maxx
	//void isTouching(PhysicalObject* otherObject);
	void cDump();
	
	void update(float dt);
	void Render(GLMatrixStack *pMVM, GLGeometryTransform *pGLGT, GLuint *texture, Camera *camIn);
	bool isTouching(PhysicalObject* otherObject, float dt);
	void setForwardVector(Vector3f v);
	Vector3f getForwardVector();
	float getWidth(){return width;}; // need this function
	float getHeight(){return height;};  // need this function
	float getDepth(){return depth;};
	float getRotation(){return alignment;};


	// Just for testing
	virtual void getPointOfImpact(float z, float y){};

	Vector3f getNormal();

};

